//
//  SQConfirmConfirmTableViewCell.m
//  energy
//
//  Created by 周曼迪 on 2021/7/12.
//

#import "SQConfirmConfirmTableViewCell.h"

#import "PickerSelectView.h"


@implementation SQConfirmConfirmTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

+(CGFloat)cellHeight:(BaseModel *)model{
    return W(111);
}

-(void)setModel:(BaseModel<BaseCellModelProtocol> *)model{
    self.queryModel = model;
    
    SQ_LOG(@"%@",self.queryModel.data.SQ_type);
//    self.queryModel.data.SQ_type //1确认，2作废，3结存，4上报
    
    if ( [MLevel isEqualToString:@"1"] ){//公司级别
        if ([self.queryModel.data.hd_steps isEqualToString:@"3"]) {//如果hd_steps==3，隐藏上报，作废和结存，隐藏确认人部门和确认人，显示整改人和验收人，界面不可点击
            
            self.lab_department.text = @"整改人";

            self.lab_people.text = @"验收人";
            self.tf_department.text = self.queryModel.data.hd_report_person_text;
            self.tf_people.text = self.queryModel.data.hd_report_department_text;
            
            self.tf_people.enabled = NO;
            self.tf_department.enabled = NO;
            self.btn_people.hidden = YES;
            self.btn_department.hidden = YES;
        }else{
            self.btn_people.hidden = NO;
            self.btn_department.hidden = NO;
            [self getHierarchy];
        }
//
     }else if ( [MLevel isEqualToString:@"2"] ){//部门级别
         if ([self.queryModel.data.SQ_type isEqualToString:@"4"]) {//4上报
             self.lab_department.text = @"确认部门";
             self.tf_department.placeholder = @"请选择部门";
             self.lab_people.text = @"确认人";
             self.tf_people.placeholder = @"请选择确认人";;
             [self companyLevel];
         }else{
             self.lab_department.text = @"整改人";
             self.tf_department.placeholder = @"请选择整改人";
             self.lab_people.text = @"验收人";
             self.tf_people.placeholder = @"请选择验收人";
             [self rectificationModel];
         }
         

           


    }else if ( [MLevel isEqualToString:@"3"] ){//班组级别
        self.lab_department.text = @"确认部门";
        self.tf_department.placeholder = @"请选择部门";
        self.lab_people.text = @"确认人";
        self.tf_people.placeholder = @"请选择确认人";
        
        [self getHierarchy];
        
        
     }

    
}




/**<#注释#>*/
- (IBAction)clickDepartment:(UIButton *)sender {
   
    
    if ( [MLevel isEqualToString:@"2"] ){
        
        if ([self.queryModel.data.SQ_type isEqualToString:@"4"]) {//4上报
            
            if (self.companyLevelModel == nil) {return;}

            self.companyLevelModel.nameArr.pickerSigleShow(self.tf_department,@"部门").finish = ^(UITextField * textField){
                SQCompanyLevelModelData * data = self.companyLevelModel.data[self.tf_department.selectIndex[0].intValue];
       
                self.cellRoller(@"department", data.os_id, data.os_name,@"0",@"");
                      
            };
        }else{
            if (self.acceptance_of_hidden_danger_rectificationModel == nil) {return;}

            self.acceptance_of_hidden_danger_rectificationModel.rectificationArr.pickerSigleShow(self.tf_department,@"整改人").finish = ^(UITextField * textField){
                SQAcceptance_of_hidden_danger_rectificationModelRectification * data = self.acceptance_of_hidden_danger_rectificationModel.rectification[self.tf_department.selectIndex[0].intValue];
                self.tf_department.text = data.m_name;
                self.cellRoller(@"department", data.m_id, data.m_name,data.m_group,data.m_number);
                      
            };
        }
        
        

     }else{
         if (self.hierarchyModel == nil) {return;}
         
         self.hierarchyModel.nameArr.pickerSigleShow(self.tf_department,@"部门").finish = ^(UITextField * textField){
             SQHierarchyModelArray * data = self.hierarchyModel.data[self.tf_department.selectIndex[0].intValue];
         
             self.cellRoller(@"department", data.os_id, data.os_name,@"0",@"");
         };

      }
    
    
    
}


//
- (IBAction)clickPeople:(UIButton *)sender {
    
    
    if ( [MLevel isEqualToString:@"2"] ){
        if ([self.queryModel.data.SQ_type isEqualToString:@"4"]) {//4上报
            
            if ([self.tf_department.text isEqualToString:@""]) {
                [CCToast showMessage:@"请选择确认部门"];
                return;
            }
           
            if (self.companyLevelModel.data[self.tf_department.selectIndex[0].intValue].nameArr.count == 0) {return;}
            
            self.companyLevelModel.data[self.tf_department.selectIndex[0].intValue].nameArr.pickerSigleShow(self.tf_people,@"确认人").finish = ^(UITextField * textField){
                SQCompanyLevelModelData * data = self.companyLevelModel.data[self.tf_department.selectIndex[0].intValue];
                SQCompanyLevelModelPersonnelArray * personnelData = data.personnel[textField.selectIndex[0].intValue];
  
                self.cellRoller(@"people",@"0",@"",personnelData.m_id, personnelData.m_name);
            };
            
           
        }else{

            if (self.acceptance_of_hidden_danger_rectificationModel == nil) {return;}

            self.acceptance_of_hidden_danger_rectificationModel.acceptorArr.pickerSigleShow(self.tf_people,@"验收人").finish = ^(UITextField * textField){
                SQAcceptance_of_hidden_danger_rectificationModelAcceptor * data = self.acceptance_of_hidden_danger_rectificationModel.acceptor[self.tf_people.selectIndex[0].intValue];
                self.tf_people.text = data.m_name;
                self.cellRoller(@"people", data.m_id, data.m_name,data.m_group,data.m_number);
                      
            };
            
        }
       
     }else {
         if ([self.tf_department.text isEqualToString:@""]) {
             [CCToast showMessage:@"请选择确认部门"];
             return;
         }
         if (self.hierarchyModel.data[self.tf_department.selectIndex[0].intValue].nameArr.count == 0) {return;}
         self.hierarchyModel.data[self.tf_department.selectIndex[0].intValue].nameArr.pickerSigleShow(self.tf_people,@"确认人").finish = ^(UITextField * textField){
             SQHierarchyModelArray * data = self.hierarchyModel.data[self.tf_department.selectIndex[0].intValue];
             SQHierarchyModelPersonnelArray * personnelData = data.personnel[textField.selectIndex[0].intValue];
        
             self.cellRoller(@"people", personnelData.m_id, personnelData.m_name,@"0",@"");
         };
      }
    
    
}

-(void)getHierarchy{
    
    self.tf_department.text = @"";
    self.tf_people.text = @"";

    
    NSString * os_level;
        if ([MLevel isEqualToString:@"1"] ) {
            os_level = MOne;
        }else if ( [MLevel isEqualToString:@"2"] || [MLevel isEqualToString:@"3"]){
            os_level = MTwo;
        }else if ( [MLevel isEqualToString:@"4"] ){
            os_level = MThree;
        }
    
    
    [SQHierarchyModel getDataWithParams:@{@"m_enterprise_id":MEnterpriseId,@"m_level":MLevel,@"os_level":os_level} WithCallBack:^(SQHierarchyModel * data) {
        self.hierarchyModel = data;
    }];
}



-(void)rectificationModel{
    self.tf_department.text = @"";
    self.tf_people.text = @"";

    [SQAcceptance_of_hidden_danger_rectificationModel getDataWithParams:@{@"m_enterprise_id":MEnterpriseId,@"m_code":MCode} WithCallBack:^(SQAcceptance_of_hidden_danger_rectificationModel * data) {
        
        self.acceptance_of_hidden_danger_rectificationModel = data;
    }];
}


-(void)companyLevel{
    self.tf_department.text = @"";
    self.tf_people.text = @"";

    [SQCompanyLevelModel getDataWithParams:@{@"m_enterprise_id":MEnterpriseId,@"m_one":MOne,@"m_one_text":MOneText} WithCallBack:^(SQCompanyLevelModel * data) {
        self.companyLevelModel = data;

    }];

}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
